//
//  JGUserManagement Controller.m
//  JGRider
//
//  Created by 单启志 on 2018/1/30.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGUserManagementController.h"
#import "JGUserManagementContentView.h"
#import "WJYAlertView.h"
#import "JGLogoutAlertView.h"
#import "JGChangeHeadPictureAlertView.h"
#import <MOFSPickerManager.h>
#import "JGPhotoManager.h"
#import "JGLoginController.h"
#import "JGNavigationController.h"
#import "JGForgetPwdController.h"//忘记密码和修改密码为同一个
#import "JGCodingHelper.h"
#import "JGRootViewHelper.h"
@interface JGUserManagementController ()<JGUserManagementContentViewDelegate,JGChangeHeadPictureAlertViewDelegate,JGLogoutAlertViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property(nonatomic,strong)JGUserManagementContentView *contView;
@property(nonatomic,strong)WJYAlertView *alertView;

@property (nonatomic, strong) UIImagePickerController *imagePickerVc;
@end

@implementation JGUserManagementController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self configSubViews];
}

-(void)configSubViews{
    self.title=@"账号管理";
    [self.view addSubview:self.contView];
}

#pragma mark contentView delegate
//修改头像
-(void)contentViewChangeIconEvent{
    JGChangeHeadPictureAlertView *alertCustomV=[[JGChangeHeadPictureAlertView alloc]initWithFrame:CGRectMake(0, 0, AdaptedWidth(280), AdaptedHeight(137))];
    alertCustomV.delegate=self;
    _alertView=[[WJYAlertView alloc]initWithCustomView:alertCustomV dismissWhenTouchedBackground:NO];
    [_alertView show];
}
//修改性别
-(void)contentViewChangeGenderEvent{

    [[MOFSPickerManager shareManger]showPickerViewWithDataArray:@[@"男",@"女",@"保密"] tag:0 title:@"请选择性别" cancelTitle:@"取消" commitTitle:@"选择" commitBlock:^(NSString *string) {
            
    } cancelBlock:^{

    }];

}
//修改生日
-(void)contentViewChangeBirthdayEvent{

    [MOFSPickerManager shareManger].datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
    [[MOFSPickerManager shareManger]showDatePickerWithTag:0 title:@"请选择生日" cancelTitle:@"取消" commitTitle:@"选择" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {

    } cancelBlock:^{

    }];
}
//修改密码
-(void)contentViewChangePwdEvent{
    JGForgetPwdController *vc=[[JGForgetPwdController alloc]init];
    vc.isChangePwd=YES;
    JGpushViewController(vc);
    
}
//退出登录
-(void)contentViewLogoutEvent{
    JGLogoutAlertView *alertCustomV=[[JGLogoutAlertView alloc]initWithFrame:CGRectMake(0, 0, AdaptedWidth(240), AdaptedHeight(105))];
    alertCustomV.delegate=self;
   _alertView=[[WJYAlertView alloc]initWithCustomView:alertCustomV dismissWhenTouchedBackground:NO];
    [_alertView show];
}

#pragma mark - 修改头像alertView代理
-(void)headPictureAlertViewCloseEvent{
    [self.alertView dismissWithCompletion:nil];
}
//相册
-(void)headPictureAlertViewPhotoEvent{
    [self.alertView dismissWithCompletion:nil];
    FQWeakSelf(self);
    [[JGPhotoManager share] photoWithMaxImagesCount:1 Controller:self callBack:^(NSArray<UIImage *> *photos, NSArray *assets) {
        weakself.contView.selectImage=photos[0];
    }];
}

//拍照
-(void)headPictureAlertViewCameraEvent{

    [self.alertView dismissWithCompletion:nil];
    FQWeakSelf(self);
    [[JGPhotoManager share]CameraWithController:self callBack:^(UIImage *image) {
        weakself.contView.selectImage=image;
    }];

}

#pragma mark - 退出登录alertView代理
-(void)LogoutAlertViewBackEvent{
    [self.alertView dismissWithCompletion:nil];
}
-(void)LogoutAlertViewConfirmEvent{

    //FQWeakSelf(self);
    [self.alertView dismissWithCompletion:^{
        //JGpopViewController;
        //
//        JGLoginController *vc=[[JGLoginController alloc]init];
//        JGNavigationController *navVc=[[JGNavigationController alloc]initWithRootViewController:vc];
//        [weakself presentViewController:navVc animated:YES completion:nil];
        [[JGCodingHelper share]loginsuccessDataEncodeWith:nil];
        [JGRootViewHelper setLoginViewController];
    }];
}

#pragma mark - getters
-(JGUserManagementContentView *)contView{
    if (!_contView) {
        _contView=[[JGUserManagementContentView alloc]initWithFrame:CGRectMake(0, self.lmj_navgationBar.height, JGScreenW, JGScreenH-self.lmj_navgationBar.height)];
        _contView.delegate=self;
    }
    return _contView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
